import 'package:flutter/material.dart';

class DashedLine extends StatelessWidget {
  final Axis axis; // 虚线的方向
  final double dashedWidth; // 虚线的宽度
  final double dashedHeight; // 虚线的高度
  final int count; // 虚线之间的空白间隔
  final Color color; // 虚线颜色
  const DashedLine(
      {super.key,
      required this.axis,
      this.dashedWidth = 1,
      this.dashedHeight = 1,
      this.count = 8,
      this.color = Colors.black});

  @override
  Widget build(BuildContext context) {
    return Center(
      child: LayoutBuilder(
          builder: (BuildContext ctx, BoxConstraints constraints) {
        return Flex(
          direction: axis,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: lineDemo(),
        );
      }),
    );
  }

  List<Widget> lineDemo() {
    return List.generate(count, (index) {
      return SizedBox(
        width: dashedWidth,
        height: dashedHeight,
        child: DecoratedBox(
          decoration: BoxDecoration(color: color),
        ),
      );
    });
  }
}
